# Import the base Model class from Flask-AppBuilder.
from flask_appbuilder import Model
# Import column types from SQLAlchemy to define the database schema.
from sqlalchemy import Column, Integer, String

# Import custom base models and mixins from the application.
from myapp.models.base import MyappModelBase
from myapp.models.helpers import AuditMixinNullable


# Get the metadata object from the base Flask-AppBuilder Model.
# This metadata is shared across all models and holds the schema information.
metadata = Model.metadata


# Define the DataClean class, which maps to the 'data_clean' table.
# This model represents a data cleaning task.
class DataClean(Model, AuditMixinNullable, MyappModelBase):
    # Specify the table name in the database.
    __tablename__ = 'data_clean'
    # Define the primary key column.
    id = Column(Integer, primary_key=True, comment='id')
    # The name of the data cleaning task.
    name = Column(String(200), nullable=True, comment='任务名称')
    # The current status of the task (e.g., "processing", "succeeded", "failed").
    status = Column(
        String(200), nullable=True, default='processing', comment='processing ,succeed ,failed'
    )
    # The ID of the input dataset (v2), corresponding to the 'dataset_v2' table.
    dataset_v2_id = Column(Integer, nullable=False, comment='输入v2数据集id,对应dataset_v2')
    # The ID of the specific version of the input dataset, corresponding to the 'dataset' table.
    version_id = Column(Integer, nullable=False, comment='输入数据集版本id，对应dataset')
    # A user-friendly display name for the input dataset, typically in "name:version" format.
    dataset_show_name = Column(String(200), nullable=True, comment='输入数据集名, v2name:version')
    # The storage path of the input dataset.
    dataset_path = Column(String(200), nullable=False, comment='输入数据集路径')
    # The type of data in the input dataset (e.g., image, audio, text).
    dataset_data_type = Column(
        String(200), nullable=True, default='', comment='数据类型，image/audio/txt/multiple/other'
    )
    # The type of annotation or labeling used in the input dataset.
    dataset_label_type = Column(String(200), nullable=True, default='', comment='label_type')
    # The storage path for the cleaned, output dataset.
    output_path = Column(String(200), nullable=True, default='', comment='输出路径')
    # The ID of the new dataset version created for the output, corresponding to the 'dataset' table.
    output_version_id = Column(
        Integer, nullable=False, comment='输出数据集version_id,对应dataset表'
    )
    # A user-friendly display name for the output dataset version.
    output_show_name = Column(String(200), nullable=True, comment='输出版本名, v2name:version')

    # The data cleaning operators or functions applied in this task, likely in a programmatic format.
    operators = Column(String(1000), nullable=True, default='', comment='算子')
    # A representation of the operators specifically for frontend display.
    operators_front = Column(
        String(2000), nullable=True, default='', comment='展示算子，仅供前端展示用'
    )
    # A human-readable description of the operators used.
    operators_desc = Column(String(200), nullable=True, default='', comment='算子描述')

    # The total number of items in the input dataset.
    total_num = Column(Integer, nullable=False, default=0, comment='总数量')
    # The number of items that have been processed so far.
    deal_num = Column(Integer, nullable=False, default=0, comment='已处理总数量')
    # The number of items classified as 'standard'.
    standard_num = Column(Integer, nullable=False, default=0, comment='标准数量')
    # The number of items classified as 'special'.
    special_num = Column(Integer, nullable=False, default=0, comment='特殊数量')
    # The number of items classified as 'sensitive'.
    sensitive_num = Column(Integer, nullable=False, default=0, comment='敏感数量')
    # The number of items filtered out during the cleaning process.
    filter_num = Column(Integer, nullable=False, default=0, comment='过滤数量')
    # The number of items that resulted in an error during processing.
    error_num = Column(Integer, nullable=False, default=0, comment='错误数量')
    # The number of duplicate items found and/or removed.
    duplicate_num = Column(Integer, nullable=False, default=0, comment='重复数量')
    # The ID of the backend processing job (e.g., a Flink job).
    job_id = Column(String(200), nullable=True, default='', comment='flink作业id')
    # A field to store any error message if the task fails.
    error_msg = Column(String(200), nullable=True, default='', comment='错误信息')
    # The geographical or logical region where the cleaning task is executed.
    region = Column(String(100), nullable=False, default='default', server_default='default', comment='地区')
